package com.sixks.app.mvc.cmd;

import com.sixks.app.domain.ExpressUser;
import com.sixks.app.mvc.cmd.exception.ExpressAPIException;
import org.apache.commons.lang3.StringUtils;

/**
 * @author colin
 * @date: 02/03/2014
 * @time: 11:09
 */
public abstract class BaseCommandAPI<T extends APIRequest> {

    protected final String HTTP_ROOT = "http://gw.api.alibaba.com/openapi/";
    /**
     * 所有请求，都使用此方法
     * @param request
     * @param user
     * @return
     * @throws ExpressAPIException
     */
    public APIResponse doCall(T request, ExpressUser user) throws ExpressAPIException {

        APIResponse response;
        if(user == null || StringUtils.isBlank(user.getAccessToken())){
            throw new ExpressAPIException("access token 没有找到");
        }
        response = handle(request,user);
        return response;
    }

    protected abstract APIResponse handle(T request, ExpressUser user) throws ExpressAPIException;

}
